#!/bin/bash

echo "Welcome to tonecast studio..."
echo "Click on the window you would like to record."

WIN_ID=$(xwininfo | awk '/Window id:/ {print $4}')

X=$(xwininfo | awk '/Absolute upper-left X:/ {print $4}')
Y=$(xwininfo | awk '/Absolute upper-left Y:/ {print $4}')
WIDTH=$(xwininfo | awk '/Width:/ {print $2}')
HEIGHT=$(xwininfo | awk '/Height:/ {print $2}')

REC="recordmydesktop -x $X -y $Y --width $WIDTH --height $HEIGHT --on-the-fly-encoding"
#REC="recordmydesktop --windowid $WIN_ID"

SC="SuperCollider:out_1 SuperCollider:out_2"
MIC="\"system:AC0_dev0_MicIn1 left\""

TITLE=recorded-`date +%Y-%m-%d`.ogv

echo "Mic source: $MIC"
echo -n "Do you want to record from the Mic? [Y/n] [Enter]"
read mic

echo "Recording to file: $TITLE\n"

if [[ "$mic" -eq "n" ]] 
then
  # Without Mic
  echo "$REC --use-jack $SC -o $TITLE"
  $REC --use-jack $SC -o $TITLE
else 
  # With Mic
  echo "$REC --use-jack $SC $MIC -o $TITLE"
  $REC --use-jack $SC $MIC -o $TITLE
fi

